/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tchat;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;

/**
 *
 * @author Hippolyte
 */
public class Message implements Serializable {

    public int id;
    public String contenu;
    public Personne p;
    public Date dateTime;

    public Message(int id, String contenu, Personne p) {
        this.id = id;
        this.contenu = contenu;
        this.p = p;
        this.dateTime = Calendar.getInstance().getTime();
//        this.dateTime = null;
    }
    

    @Override
    public String toString() {
        
        String espaces = "";
        int nbEsp = 25 - p.getNom().length();
        
        for(int i = 0 ; i < nbEsp ; i ++) {
            espaces += " ";
        }
        
        return ("[" + dateTime.toString().substring(11, 19) + "]" + espaces 
                + "<" + p.getNom() + ">  " + contenu);
    }
    
}
